package com.situ.day7;

import org.junit.Test;


public class StringDemo {

    @Test
    public void test1() {
        // "abc" 常量字符串，他也是一个对象
        String str1 = "abc";
        String str2 = new String("abc");
        String str3 = "abc";
        // "=="比较的是他们的地址值
        System.out.println(str1 == str2);// false
        System.out.println(str1 == str3);// true
        System.out.println(str2 == str3);// false
        // equals：比较里面的内容是不是相等
        System.out.println(str1.equals(str2));
        System.out.println(str1.equals(str3));
        System.out.println(str2.equals(str3));
    }

    @Test
    public void test2() {
        int[] array = {3, 45, 6};
        System.out.println(array.length);
        String str = "java AndroidA";
        System.out.println(str.length());// 13
        char[] chars = str.toCharArray();
        System.out.println(str.charAt(5));// A
        System.out.println(str.indexOf('A'));// 5
        System.out.println(str.indexOf('A', 6));// 12
        System.out.println(str.indexOf("And"));// 5
        System.out.println(str.lastIndexOf('A'));// 12
    }

    @Test
    public void tes2() {
        String str1 = "abc";
        String str2 = "Abc";
        System.out.println(str1 == str2);// false
        // equals默认区分大小写
        System.out.println(str1.equals(str2));// false
        System.out.println(str1.equalsIgnoreCase(str2));//true

        String str = "java AndroidA";
        System.out.println(str.contains("And"));// true
        // prefix：前缀  suffix: 后缀
        // positive: 积极、正数、正极  negative: 消极、负数、负极
        System.out.println(str.startsWith("ja"));// true
        System.out.println(str.endsWith("idA"));// true
        // offset：偏移
        System.out.println(str.startsWith("And", 5));// true
        System.out.println(str.isEmpty());// false
        String str3 = ""; // 空字符串
        // char ch = '';
        System.out.println(str3.isEmpty());// true
        // "abc"常量字符串也是一个对象
        System.out.println("abc".isEmpty());// false
        System.out.println("".isEmpty());// true
    }

    @Test
    public void test88() {
        String str = "java AndroidA";
        char[] chars = str.toCharArray();
        char[] array = {'j', 'a', 'v', 'a', ' ', 'A', 'n', 'd'};
        String str1 = new String(array);
        System.out.println(str1);
    }

    @Test
    public void test882() {
        String str = "java AndroidA";
        String newStr = str.replace('A', 'B');
        System.out.println(str);// java AndroidA
        System.out.println(newStr);// java BndroidB
    }

    @Test
    public void test83() {
        String str = "java AndroidA"; // " "
        String[] array = str.split(" ");
        for (String s : array) {
            System.out.println(s);
        }
    }

    @Test
    public void test67() {
        // subtree: 子树
        String str = "java AndroidA";
        System.out.println(str.substring(5));// AndroidA
        System.out.println(str.substring(5, 10));// Andro
    }

    @Test
    public void test637() {
        String str = "    zhansgan   ";
        System.out.println(str);
        System.out.println(str.trim());
    }

    @Test
    public void test89() {
        // Required type: StringBuffer
        // Provided: String
        // StringBuffer stringBuffer = "abc";

        // 1、String长度是不可改变的，StringBuffer、StringBuilder长度是可变的。
        String str1 = "abc";
        String str2 = "def";
        String str3 = "ghi";
        String str4 = "fgfg";
        str1 = str1 + str2 + str3 + str4; // new一个新的字符串对象赋值给str
        System.out.println(str1);

        StringBuffer stringBuffer = new StringBuffer("abc");
//        stringBuffer.append(str2);
//        stringBuffer.append(str3);
//        stringBuffer.append(str4);
        // 链式编程
        stringBuffer.append(str2).append(str3).append(str4);
        System.out.println(stringBuffer);

        StringBuilder stringBuilder = new StringBuilder("abc");
        stringBuilder.append(str2);
        stringBuilder.append(str3);
        stringBuilder.append(str4);
        System.out.println(stringBuilder);
    }

    @Test
    public void test78() {
        Integer integer1 = 12;
        // 装箱
        Integer integer2 = new Integer(12);
        // 拆箱
        // int i = integer1.intValue();
        integer1 = integer1 + 23;

        System.out.println(integer1 + integer2 + 4);

        int i = Integer.parseInt("12");
        Integer i1 = Integer.valueOf(12);
        Integer i2 = Integer.valueOf("12");


    }

    @Test
    public void test899() {
        String str = "3.14";
        System.out.println(str + 1);// 3.141
        double d = Double.parseDouble(str);
        System.out.println(d + 1);// 4.140000000000001

        String str1 = "false";
        boolean bool = Boolean.parseBoolean(str1);
    }

    @Test
    public void tes888() {
        String str = "3.14a";
        double d = Double.parseDouble(str);
        System.out.println(d);
    }

    @Test
    public void test55() {
        // StringIndexOutofBoundsException
        String str = "java";
        System.out.println(str.charAt(4));

    }

    @Test
    public void test44() {
        String str = "I Love Java！";
        System.out.println(str.toLowerCase());
        String s = lowerCase(str);
    }

    private String lowerCase(String str) {

        return "";
    }

}
